package com.ruoyi.system.controller;

import com.ruoyi.common.auth.annotation.HasPermissions;
import com.ruoyi.common.log.annotation.OperLog;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.service.ISysInsuranceDetailsService;

import java.util.List;

/**
 * 投保单下载 提供者
 * 
 * @author ruoyi
 * @date 2021-09-17
 */
@Api(value = "保单号管理和支付管理")
@RestController
@RequestMapping("sysInsuranceDetails")
public class SysInsuranceDetailsController extends BaseController
{
	
	@Autowired
	private ISysInsuranceDetailsService sysInsuranceDetailsService;
	
	/**
	 * 查询${tableComment}
	 */
	@ApiOperation(value = "根据id查询")
	@ApiImplicitParam(name = "id", value = "id", required = true)
	@GetMapping("get/{id}")
	public SysInsuranceDetails get(@PathVariable("id") Long id)
	{
		return sysInsuranceDetailsService.selectSysInsuranceDetailsById(id);
		
	}
	
	/**
	 * 查询投保单下载列表
	 */
	@ApiOperation(value = "查询保单号管理列表及根据条件查询列表")
	@GetMapping("list")
	public R list(SysInsuranceDetails sysInsuranceDetails)
	{
		startPage();
        return result(sysInsuranceDetailsService.selectSysInsuranceDetailsList(sysInsuranceDetails));
	}

	/**
	 * 查询投保单下载列表
	 */
	@ApiOperation(value = "查询支付管理列表及根据条件查询列表")
	@GetMapping("payList")
	public R payList(SysInsuranceDetails sysInsuranceDetails)
	{
		startPage();
		return result(sysInsuranceDetailsService.selectPaySysInsuranceDetailsList(sysInsuranceDetails));
	}
	
	
	/**
	 * 新增保存投保单下载
	 */
	@ApiOperation(value = "新增保存保单号管理和支付管理")
	@PostMapping("save")
	public R addSave(@RequestBody SysInsuranceDetails sysInsuranceDetails)
	{		
		return toAjax(sysInsuranceDetailsService.insertSysInsuranceDetails(sysInsuranceDetails));
	}

	/**
	 * 修改保存投保单下载
	 */
	@ApiOperation(value = "修改保存保单号管理和支付管理")
	@PostMapping("update")
	public R editSave(@RequestBody SysInsuranceDetails sysInsuranceDetails)
	{		
		return toAjax(sysInsuranceDetailsService.updateSysInsuranceDetails(sysInsuranceDetails));
	}

	/**
	 * 更新保单号和保单生效时间
	 */
	@ApiOperation(value = "更新保单号和保单生效时间")
	@PostMapping("updateLossPolicyAndInsuranceStartdate")
	public R updateLossPolicyAndInsuranceStartdate(@RequestBody UpdateLossPolicyAndInsuranceStartdate updateLossPolicyAndInsuranceStartdate)
	{
		return toAjax(sysInsuranceDetailsService.updateLossPolicyAndInsuranceStartdate(updateLossPolicyAndInsuranceStartdate.getId(),updateLossPolicyAndInsuranceStartdate.getLossPolicy(),updateLossPolicyAndInsuranceStartdate.getInsuranceStartdate()));
	}

	/**
	 * 更新支付状态和支付时间
	 */
	@ApiOperation(value = "更新支付状态和支付时间")
	@PostMapping("updatePayStatusAndPayTime")
	public R updatePayStatusAndPayTime(@RequestBody List<UpdatePayStatusAndPayTime> updatePayStatusAndPayTimeList)
	{
		return toAjax(sysInsuranceDetailsService.updatePayStatusAndPayTime(updatePayStatusAndPayTimeList));
	}
	
	/**
	 * 删除${tableComment}
	 */
	@ApiOperation(value = "删除")
	@ApiImplicitParam(name = "ids", value = "ids", required = true)
	@PostMapping("remove")
	public R remove(String ids)
	{		
		return toAjax(sysInsuranceDetailsService.deleteSysInsuranceDetailsByIds(ids));
	}

	@ApiOperation(value = "导出投保清单execl")
	@ApiImplicitParam(name = "ids", value = "ids", required = true)
	@OperLog(title = "投保单清单", businessType = BusinessType.EXPORT)
	@HasPermissions("system:sysInsuranceDetailsList:export")
	@PostMapping("/export")
	public R export(String ids)
	{
		List<InsuranceDetailsExport> list = sysInsuranceDetailsService.selectInsuranceDetailsExportList(Long.valueOf(ids));
		ExcelUtil<InsuranceDetailsExport> util = new ExcelUtil<InsuranceDetailsExport>(InsuranceDetailsExport.class);
		return util.exportExcel(list, "投保信息");
	}

}
